package com.shaoshaohuo.app.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shaoshaohuo.app.R;

public class BusinessEnterActivity extends AppCompatActivity implements View.OnClickListener {
    /**
     * tobar
     */
    private ImageView order_tobar_back;
    private TextView order_tobar_enter;
    private ImageView order_tobar_right;
    private LinearLayout order_layout_topbar_left;


    private Button business_enter_button;
    private TextView hezuo_xieyi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_enter);
        initView();
        initListener();
    }

    private void initListener() {
        business_enter_button.setOnClickListener(this);
        hezuo_xieyi.setOnClickListener(this);
        order_layout_topbar_left.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                }
        );
    }


    private void initView() {
        /**
         * tobar
         * */
        order_tobar_back = (ImageView) findViewById(R.id.imageview_topbar_left_backImage);
        order_tobar_back.setVisibility(View.VISIBLE);
        order_tobar_back.setImageResource(R.mipmap.return_key);
        order_tobar_enter = (TextView) findViewById(R.id.toolbar_topname);
        order_tobar_enter.setText("商家入驻");
        order_tobar_right = (ImageView) findViewById(R.id.imageview_message);
        order_tobar_right.setVisibility(View.GONE);
        order_layout_topbar_left = (LinearLayout) findViewById(R.id.layout_topbar_left);
        order_layout_topbar_left.setVisibility(View.VISIBLE);


        business_enter_button = (Button) findViewById(R.id.business_enter_button);
        hezuo_xieyi = (TextView) findViewById(R.id.hezuo_xieyi);
        String string = hezuo_xieyi.getText().toString().trim();
        SpannableStringBuilder builder = new SpannableStringBuilder(string);
//        ForegroundColorSpan redSpan = new ForegroundColorSpan(getResources().getColor(R.color.color_49b152));
        String substring = "《农场战略合作协议》";
        SpannableString spannableString = new SpannableString(substring);
        spannableString.setSpan(new ClickableSpan() {
            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor(getResources().getColor(R.color.color_49b152));//设置文件颜色
                ds.setUnderlineText(false);
            }

            @Override
            public void onClick(View widget) {
//                ToastUtil.toast("啥玩意");
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), UserFarmAgreementActivity.class);
                startActivity(intent);
            }
        }, 0, substring.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//        builder.setSpan(redSpan, string.length() - 10, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        hezuo_xieyi.setHighlightColor(Color.TRANSPARENT);
        hezuo_xieyi.append(spannableString);
        hezuo_xieyi.setMovementMethod(LinkMovementMethod.getInstance());//开始响应点击事件
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.business_enter_button:
                intent.setClass(this, BusinessApllyMessageActivity.class);
                startActivity(intent);
                break;
            case R.id.hezuo_xieyi:
                //跳协议
                break;
        }
    }
}
